﻿using System.Drawing;
using System.Media;
using System.Windows.Forms;

namespace MyPaint
{
    /// <summary>
    /// 顶部弹窗提示
    /// </summary>
    public partial class FrmMessageBox : Form
    {
        private Timer timer1;

        /// <summary>
        /// 构造函数+3
        /// </summary>
        /// <param name="point">父窗体起始点</param>
        /// <param name="width">父窗体宽度</param>
        /// <param name="msg">消息内容</param>
        public FrmMessageBox(Point point, int width, string msg)
        {
            InitializeComponent();
            this.Location = new Point((width - this.Width) / 2 + point.X, point.Y);
            this.ShowMsg.Text = msg;

            this.Load += (s, e) =>
            {
                //提示信息居中显示
                ShowMsg.Location = new Point(
                    (this.Width - ShowMsg.Width) / 2,
                    (this.Height - ShowMsg.Height) / 2
                    );
                timer1.Interval = 888;//显示时间
                timer1.Start();
            };

            timer1 = new Timer();
            timer1.Tick += (s, e) =>
            {
                timer1.Interval = 30;
                this.Opacity -= 0.1;
                if (this.Opacity == 0)
                {
                    this.Close();
                }
            };

            //播放系统提示音
            SystemSounds.Beep.Play();
        }

        /// <summary>
        /// 构造函数+4
        /// </summary>
        /// <param name="point"></param>
        /// <param name="width"></param>
        /// <param name="msg"></param>
        /// <param name="color"></param>
        public FrmMessageBox(Point point, int width, string msg, Color backColor) : this(point, width, msg)
        {
            this.BackColor = backColor;
        }
    }
}
